#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;

void swap(int* a, int* b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

int fastSort1(int* arr, int left, int right)
{
	int key = left;
	while (left<right)
	{
		while (left < right && arr[right] >= arr[key])
		{
			right--;
		}
		while (left < right && arr[left] <= arr[key])
		{
			left++;
		}
		swap(&arr[left], &arr[right]);
	}
	swap(&arr[key], &arr[right]);
	return left;
}

void fastSort(int* arr, int left, int right)
{
	if (left >= right)return;

	int key = fastSort1(arr, left, right);
	fastSort(arr, 0, key - 1);
	fastSort(arr, key + 1, right);
}

void Print(int* arr,int sz)
{
	for (int i = 0; i < sz; i++)
		cout << arr[i] << " ";
}

template<class T>
int add(T a, T b)
{
	cout << "T add(T a, T b)" << endl;
	return a + b;
}
template<>
int add<int*>(int* a, int* b)
{
	cout << "T add<T*>(T* a, T* b)" << endl;
	return *a + *b;
}

void justDown(int* arr, int parent,int sz)
{
	int child = parent * 2 + 1;
	while (child<sz)
	{
		if (child + 1 < sz && arr[child + 1] > arr[child])child++;
		if (arr[child] > arr[parent])
		{
			swap(&arr[child], &arr[parent]);
			parent = child;
			child = parent * 2 + 1;
		}
		else break;
	}
}

void testHeap(int* arr, int sz)
{
	for (int i = (sz - 1 - 1) / 2; i >= 0; i--)
	{
		justDown(arr, i, sz);
	}

	int end = sz - 1;
	while (end)
	{
		swap(&arr[0], &arr[end]);
		end--;
		justDown(arr, 0, end);
	}
}

int main(int argc, char* argv[])
{
	//int arr[] = { 50,6,3,9,45,12,2,0,7,88 };
	//int sz = sizeof(arr) / sizeof(int);
	//Print(arr, sz);
	//testHeap(arr, sz);
	////fastSort(arr, 0, sz - 1);
	//cout << endl;
	//Print(arr, sz);
	
	//cout<<add(5, 3);
	int a = 3, b = 5;
	add(&a,&b);
	return 0;
}